#region Header Licence
//  NKnobMan, Copyright 2009, Alexandre MUTEL.
// 
//  This is free software; you can redistribute it and/or modify it
//  under the terms of the GNU Lesser General Public License as
//  published by the Free Software Foundation; either version 2.1 of
//  the License, or (at your option) any later version.
// 
//  This software is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//  Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public
//  License along with this software; if not, write to the Free
//  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
//  02110-1301 USA, or see the FSF site: http://www.fsf.org.
#endregion
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace NKnobMan
{
    public class Log
    {
        private Log()
        {
        }

        private static TraceSwitch traceSwitch = new TraceSwitch("NKnobMan","Log for NKnobMan", "Info");

        public static TraceSwitch TraceSwitch
        {
            get
            {
                return traceSwitch;
            }
        }

        public static void Warn(string message)
        {
            if (traceSwitch.TraceWarning)
                Trace.WriteLine(message, TraceLevel.Warning.ToString());
        }

        public static void Warn(string message, params object[] args)
        {
            if ( traceSwitch.TraceWarning )
                Trace.WriteLine(string.Format(message, args), TraceLevel.Warning.ToString());
        }

        public static void Error(string message)
        {
            if (traceSwitch.TraceError)
                Trace.WriteLine(message, TraceLevel.Error.ToString());
        }

        public static void Error(Exception ex, string message)
        {
            if (traceSwitch.TraceError)
                Trace.WriteLine(message + " Exception: " + ex, TraceLevel.Error.ToString());
        }

        public static void Error(string message, params object[] args)
        {
            if (traceSwitch.TraceError)
                Trace.WriteLine(string.Format(message, args), TraceLevel.Error.ToString());
        }

        public static void Error(Exception ex, string message, params object[] args)
        {
            string fullMessage = string.Format(message, args);
            if (traceSwitch.TraceError)
                Trace.WriteLine(fullMessage + " Exception: " + ex, TraceLevel.Error.ToString());
        }

        public static void ErrorMessageBox(string message, params object[] args)
        {
            string fullMessage = string.Format(message, args);
            if (traceSwitch.TraceError)
                Trace.WriteLine(fullMessage, TraceLevel.Error.ToString());
            MessageBox.Show(fullMessage, "NKnobMan Plugin", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void ErrorMessageBox(Exception ex, string message, params object[] args)
        {
            string fullMessage = string.Format(message, args);
            if (traceSwitch.TraceError)
                Trace.WriteLine(fullMessage + " Exception: " + ex, TraceLevel.Error.ToString());
            MessageBox.Show(string.Format(fullMessage, args), "NKnobMan Plugin", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        //public static void Info(string message)
        //{
        //    if (traceSwitch.TraceInfo)
        //        Trace.WriteLine(message, TraceLevel.Info.ToString());
        //}

        public static void Info(string message)
        {
            if (traceSwitch.TraceInfo)
                Trace.WriteLine(message, TraceLevel.Info.ToString());
        }

        public static void Info(string message, params object[] args)
        {
            if (traceSwitch.TraceInfo)
                Trace.WriteLine(string.Format(message,args), TraceLevel.Info.ToString());
        }

        public static void Verbose(string message)
        {
            if (traceSwitch.TraceVerbose)
                Trace.WriteLine(message, TraceLevel.Verbose.ToString());
        }

        public static void Verbose(string message, params object[] args)
        {
            if (traceSwitch.TraceVerbose)
                Trace.WriteLine(string.Format(message, args), TraceLevel.Verbose.ToString());
        }
    }
}